/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CommonData.DataLayer;

import DataModel.Country;
import Utilities.*;
import java.sql.ResultSet;
import java.util.*;

/**
 *
 * @author Rainiero
 */
public class CommonDataDataManager {

    // <editor-fold defaultstate="collapsed" desc="Singleton">
    private static CommonDataDataManager _instance = new CommonDataDataManager();

    private CommonDataDataManager()
    {
    }

    public static CommonDataDataManager GetInstance()
    {
        return _instance;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Public Methods">
    public Country[] GetCountries()
    {
        DataAccesor accesor = DataAccesor.GetInstance();
        String spName = Constants.SP_NAME_GET_COUNTRIES;
        SQLParameter[] parameters = new SQLParameter[0];
        try
        {
            ResultSet result = accesor.ExecuteInputSP(spName, parameters);
            LinkedList<Country> addedCountries = new LinkedList<Country>();
            while(result.next())
            {
                String name = result.getString(Constants.SP_COLUMN_GET_COUNTRIES_NAME);
                int id = result.getInt(Constants.SP_COLUMN_GET_COUNTRIES_ID);
                addedCountries.add(new Country(id, name));
            }
            result.close();
            Country[] countries = new Country[addedCountries.size()];
            return addedCountries.toArray(countries);
        }
        catch(Exception ex)
        {
            return null;
        }
    }
    // </editor-fold>

}
